package graph.entities;

import static ogl.vecmathimp.FactoryDefault.vecmath;
import graph.Entity;
import graph.Part;
import ogl.vecmath.Matrix;
import ogl.vecmath.Vector;
import ogl.vecmathimp.MatrixImp;

public class Driver extends Entity {

	float rotLeft = 0f;
	float rotRight = 0f;

	boolean first = true;

	public Driver(Part p) {
		super(p);
	}

	@Override
	public void simulate(EntityType et, float elapsed) {
		MatrixImp m = super.getPart().getMatrix();
		MatrixImp modelMatrix = m.getTranslation();

		Matrix translationMatrix = vecmath.translationMatrix(0f, 0f, 0f);

		if (et == EntityType.WalkRight) {
			translationMatrix = vecmath.translationMatrix(elapsed * 2, 0, 0);
		} else if (et == EntityType.WalkLeft) {
			translationMatrix = vecmath.translationMatrix(-elapsed * 2, 0, 0);
		} else if (et == EntityType.WalkBackward) {
			translationMatrix = vecmath.translationMatrix(0, 0, elapsed * 2);
		} else if (et == EntityType.WalkForward) {
			translationMatrix = vecmath.translationMatrix(0, 0, -elapsed * 2);
		} else if (et == EntityType.RotateCamRight) {
			rotRight += elapsed;
		} else if (et == EntityType.RotateCamLeft) {
			rotLeft += elapsed;
		}

		modelMatrix = (MatrixImp) modelMatrix
				.mult(vecmath.rotationMatrix(0, 1, 0, rotRight - rotLeft))
		.mult(translationMatrix);

		this.getPart().setMatrix(modelMatrix);
	}

}
